//
//  AdoptHeaderView.m
//  PigMarket
//
//  Created by mac on 2019/3/28.
//  Copyright © 2019 felix.pigmarket.oc. All rights reserved.
//

#import "AdoptHeaderView.h"

@interface AdoptHeaderView ()<SDCycleScrollViewDelegate>

@property (nonatomic, strong) NSMutableArray *imageURLArr;

@property (nonatomic, strong) UIView *messageView;

@property (nonatomic, strong) UIView *bgView;

@property (nonatomic, strong) UILabel *tipLab;

@property (nonatomic, strong) UIImageView *messageIcon;

@property (nonatomic, strong) UIImageView *icon;

@property (nonatomic, strong) UIImageView *goingIcon;

@property (nonatomic, strong) UIButton *registBtn;

@end

@implementation AdoptHeaderView

#pragma mark - init method
//- (instancetype)initWithFrame:(CGRect)frame
//{
//    self = [super initWithFrame:frame];
//    if (self) {
//        [self initView];
//        [self initLayout];
//    }
//    return self;
//}
//
//- (void)initView {
//    // 添加子控件
//    [self addSubview:self.cycleView];
//    [self addSubview:self.messageView];
//    [self.messageView addSubview:self.bgView];
//    [self.bgView addSubview:self.messageIcon];
//    [self.bgView addSubview:self.tipLab];
//    [self.bgView addSubview:self.goingIcon];
//    [self addSubview:self.registBtn];
//
//}

- (void)setupUI{
    
    [self addSubview:self.cycleView];
    [self addSubview:self.messageView];
    [self.messageView addSubview:self.bgView];
    [self.bgView addSubview:self.messageIcon];
    [self.bgView addSubview:self.tipLab];
    [self.bgView addSubview:self.goingIcon];
    [self.bgView addSubview:self.registBtn];

}

- (void)setupLayout {

    self.height = 260 +TJ_StatusBarHeight_Define;
    {
        self.cycleView.size = CGSizeMake(KScreenWidth, self.height - 44);
        self.cycleView.mj_y = self.cycleView.mj_x = 0;
    }
    
    
    {
        self.messageView.size = CGSizeMake(KScreenWidth, 54);
        self.messageView.mj_y = _cycleView.bottom - 10;
        self.messageView.mj_x = 0;
    }
    
    
    {
        self.bgView.size = CGSizeMake(KScreenWidth - 30, 44);
        self.bgView.mj_x = 15;
        self.bgView.mj_y = 15;
    }
    
    
    {
        self.messageIcon.size = CGSizeMake(59, 40);
        self.messageIcon.mj_x = self.messageIcon.mj_y = 0;
    }
    
    {
        _registBtn.size = CGSizeMake(62, 24);
        _registBtn.mj_y = (_bgView.height - _registBtn.height)/2.0;
        _registBtn.mj_x = _bgView.width - _registBtn.width - 5;
        
//        _registBtn.mj_y = 100;
//        _registBtn.mj_x = 100;
    }
    
    switch (self.ticketType) {
        case 0:
            {
                _goingIcon.hidden = YES;
                _registBtn.hidden = YES;
                _tipLab.text = @"省钱小助手：完成任务赚豚券";
            }
            break;
        
        case 1:
            {
                _goingIcon.hidden = NO;
                _registBtn.hidden = YES;
                _tipLab.text = self.couponsStr;
            }
            break;
            
        default:
            {
                _goingIcon.hidden = YES;
                _registBtn.hidden = NO;
                _tipLab.text = @"完成任务可得60元豚券";
            }
            break;
    }
    
    {
        self.tipLab.size = CGSizeMake(_bgView.width - _messageIcon.width - 40, 44);
        _tipLab.mj_x = _messageIcon.right + 5;
        _tipLab.mj_y = 0;
    }
    
    
    {
        self.goingIcon.size = CGSizeMake(40, 44);
        self.goingIcon.mj_x = _tipLab.right;
        self.goingIcon.mj_y = 0;
    }
}


#pragma mark - getter and setter

- (void)setCouponsStr:(NSString *)couponsStr {
    _couponsStr = couponsStr;
    [self setupLayout];
}


- (void)setTicketType:(TicketType)ticketType{
    _ticketType = ticketType;
    [self setupLayout];
}

- (SDCycleScrollView *)cycleView {
    if (!_cycleView) {
        _cycleView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:nil];
        _cycleView.pageControlAliment = SDCycleScrollViewPageContolAlimentRight;
        _cycleView.currentPageDotColor = [UIColor primaryColor];
        _cycleView.autoScrollTimeInterval = 2.0;
        _cycleView.backgroundColor = KClearColor;
        _cycleView.pageDotImage = [UIImage imageNamed:@"scrollview_white"];
        _cycleView.currentPageDotImage = [UIImage imageNamed:@"scrollview_green"];
        _cycleView.pageControlBottomOffset = 12;
        _cycleView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        _cycleView.placeholderImage = [UIImage imageNamed:@"placeholder_large"];
    }
    return _cycleView;
}


- (UIView *)messageView {
    if (!_messageView) {
        _messageView = [[UIView alloc] init];
        _messageView.backgroundColor = [UIColor whiteColor];
        _messageView.userInteractionEnabled = YES;
        
        CAShapeLayer *maskLayer = [CAShapeLayer layer];
        UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, KScreenWidth, 55) byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight cornerRadii:CGSizeMake(8, 8)];
        maskLayer.path = path.CGPath;
        
        _messageView.layer.mask = maskLayer;
        
    }
    return _messageView;
}


- (UIView *)bgView{
    
    if (!_bgView) {
        _bgView = [UIView makeViewBgColor:UIColorFromRGB(0xFFF3DE) cornerRadius:3];
        _bgView.userInteractionEnabled = YES;
    }
    return _bgView;
}


- (UIImageView *)messageIcon {
    if (!_messageIcon) {
        _messageIcon  = [[UIImageView alloc] init];
        _messageIcon.image = [UIImage imageNamed:@"meat_adopt_gift"];
    }
    return _messageIcon;
}


- (UIImageView *)goingIcon {
    if (!_goingIcon) {
        _goingIcon  = [[UIImageView alloc] init];
        _goingIcon.image = [UIImage imageNamed:@"meat_adopt_hand"];
        _goingIcon.contentMode = UIViewContentModeLeft;
        _goingIcon.userInteractionEnabled = YES;
    }
    return _goingIcon;
}

- (UIButton *)registBtn{
    
    if (!_registBtn) {
        _registBtn = [UIButton makeButtonWithText:@"去注册" textColor:UIColorFromRGB(0xDE6402) font:mFont(12) textAliment:1 cornerRadius:12];
        _registBtn.layer.borderColor = UIColorFromRGB(0xFFB22B).CGColor;
        _registBtn.layer.borderWidth = 1;
        _registBtn.backgroundColor = UIColorFromRGB(0xFFF3DE);
        @weakify(self);
        _registBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealRegistBlock) {
                self.dealRegistBlock();
            }
        };
    }
    return _registBtn;
}

- (UILabel *)tipLab{
    
    if (!_tipLab) {
        _tipLab = [UILabel makeLabelWithText:@"" textColor:UIColorFromRGB(0xDE6402) font:mFont(13) textAliment:0];
    }
    return _tipLab;
}

- (NSMutableArray *)imageURLArr {
    if (!_imageURLArr) {
        _imageURLArr = [[NSMutableArray alloc] init];
    }
    return _imageURLArr;
}

@end
